home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / distutils / sysconfig.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-11-11  |  17KB  |  515 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. """Provide access to Python's configuration information.  The specific
  5. configuration variables available depend heavily on the platform and
  6. configuration.  The values may be retrieved using
  7. get_config_var(name), and the list of variables is available via
  8. get_config_vars().keys().  Additional convenience functions are also
  9. available.
  10.  
  11. Written by:   Fred L. Drake, Jr.
  12. Email:        <fdrake@acm.org>
  13. """
  14. __revision__ = '$Id: sysconfig.py 75023 2009-09-22 19:31:34Z ronald.oussoren $'
  15. import os
  16. import re
  17. import string
  18. import sys
  19. from distutils.errors import DistutilsPlatformError
  20. PREFIX = os.path.normpath(sys.prefix)
  21. EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
  22. project_base = os.path.dirname(os.path.abspath(sys.executable))
  23. if os.name == 'nt' and 'pcbuild' in project_base[-8:].lower():
  24.     project_base = os.path.abspath(os.path.join(project_base, os.path.pardir))
  25.  
  26. if os.name == 'nt' and '\\pc\\v' in project_base[-10:].lower():
  27.     project_base = os.path.abspath(os.path.join(project_base, os.path.pardir, os.path.pardir))
  28.  
  29. if os.name == 'nt' and '\\pcbuild\\amd64' in project_base[-14:].lower():
  30.     project_base = os.path.abspath(os.path.join(project_base, os.path.pardir, os.path.pardir))
  31.  
  32.  
  33. def _python_build():
  34.     for fn in ('Setup.dist', 'Setup.local'):
  35.         if os.path.isfile(os.path.join(project_base, 'Modules', fn)):
  36.             return True
  37.     
  38.     return False
  39.  
  40. python_build = _python_build()
  41.  
  42. def get_python_version():
  43.     """Return a string containing the major and minor Python version,
  44.     leaving off the patchlevel.  Sample return values could be '1.5'
  45.     or '2.2'.
  46.     """
  47.     return sys.version[:3]
  48.  
  49.  
  50. def get_python_inc(plat_specific = 0, prefix = None):
  51.     """Return the directory containing installed Python header files.
  52.  
  53.     If 'plat_specific' is false (the default), this is the path to the
  54.     non-platform-specific header files, i.e. Python.h and so on;
  55.     otherwise, this is the path to platform-specific header files
  56.     (namely pyconfig.h).
  57.  
  58.     If 'prefix' is supplied, use it instead of sys.prefix or
  59.     sys.exec_prefix -- i.e., ignore 'plat_specific'.
  60.     """
  61.     if prefix is None:
  62.         if not plat_specific or EXEC_PREFIX:
  63.             pass
  64.         prefix = PREFIX
  65.     
  66.     if os.name == 'posix':
  67.         return python_build(os.path.join, prefix, 'include' + 'python' + get_python_version() if python_build else '')
  68.     if os.name == 'nt':
  69.         return os.path.join(prefix, 'include')
  70.     if os.name == 'mac':
  71.         if plat_specific:
  72.             return os.path.join(prefix, 'Mac', 'Include')
  73.         return os.path.join(prefix, 'Include')
  74.     os.name == 'mac'
  75.     if os.name == 'os2':
  76.         return os.path.join(prefix, 'Include')
  77.     raise DistutilsPlatformError("I don't know where Python installs its C header files on platform '%s'" % os.name)
  78.  
  79.  
  80. def get_python_lib(plat_specific = 0, standard_lib = 0, prefix = None):
  81.     """Return the directory containing the Python library (standard or
  82.     site additions).
  83.  
  84.     If 'plat_specific' is true, return the directory containing
  85.     platform-specific modules, i.e. any module from a non-pure-Python
  86.     module distribution; otherwise, return the platform-shared library
  87.     directory.  If 'standard_lib' is true, return the directory
  88.     containing standard Python library modules; otherwise, return the
  89.     directory for site-specific modules.
  90.  
  91.     If 'prefix' is supplied, use it instead of sys.prefix or
  92.     sys.exec_prefix -- i.e., ignore 'plat_specific'.
  93.     """
  94.     if not not prefix:
  95.         pass
  96.     is_default_prefix = os.path.normpath(prefix) in ('/usr', '/usr/local')
  97.     if prefix is None:
  98.         if not plat_specific or EXEC_PREFIX:
  99.             pass
  100.         prefix = PREFIX
  101.     
  102.     if os.name == 'posix':
  103.         libpython = os.path.join(prefix, 'lib', 'python' + get_python_version())
  104.         if standard_lib:
  105.             return libpython
  106.         if is_default_prefix and 'PYTHONUSERBASE' not in os.environ and 'real_prefix' not in sys.__dict__:
  107.             return os.path.join(libpython, 'dist-packages')
  108.         return os.path.join(libpython, 'site-packages')
  109.     os.name == 'posix'
  110.     if os.name == 'nt':
  111.         if standard_lib:
  112.             return os.path.join(prefix, 'Lib')
  113.         if get_python_version() < '2.2':
  114.             return prefix
  115.         return os.path.join(prefix, 'Lib', 'site-packages')
  116.     os.name == 'nt'
  117.     if os.name == 'mac':
  118.         if plat_specific:
  119.             if standard_lib:
  120.                 return os.path.join(prefix, 'Lib', 'lib-dynload')
  121.             return os.path.join(prefix, 'Lib', 'site-packages')
  122.         plat_specific
  123.         if standard_lib:
  124.             return os.path.join(prefix, 'Lib')
  125.         return os.path.join(prefix, 'Lib', 'site-packages')
  126.     os.name == 'mac'
  127.     if os.name == 'os2':
  128.         if standard_lib:
  129.             return os.path.join(prefix, 'Lib')
  130.         return os.path.join(prefix, 'Lib', 'site-packages')
  131.     os.name == 'os2'
  132.     raise DistutilsPlatformError("I don't know where Python installs its library on platform '%s'" % os.name)
  133.  
  134.  
  135. def customize_compiler(compiler):
  136.     """Do any platform-specific customization of a CCompiler instance.
  137.  
  138.     Mainly needed on Unix, so we can plug in the information that
  139.     varies across Unices and is stored in Python's Makefile.
  140.     """
  141.     if compiler.compiler_type == 'unix':
  142.         (cc, cxx, opt, cflags, opt, extra_cflags, basecflags, ccshared, ldshared, so_ext) = get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS', 'OPT', 'EXTRA_CFLAGS', 'BASECFLAGS', 'CCSHARED', 'LDSHARED', 'SO')
  143.         if 'CC' in os.environ:
  144.             cc = os.environ['CC']
  145.         
  146.         if 'CXX' in os.environ:
  147.             cxx = os.environ['CXX']
  148.         
  149.         if 'LDSHARED' in os.environ:
  150.             ldshared = os.environ['LDSHARED']
  151.         
  152.         if 'CPP' in os.environ:
  153.             cpp = os.environ['CPP']
  154.         else:
  155.             cpp = cc + ' -E'
  156.         if 'LDFLAGS' in os.environ:
  157.             ldshared = ldshared + ' ' + os.environ['LDFLAGS']
  158.         
  159.         if 'BASECFLAGS' in os.environ:
  160.             basecflags = os.environ['BASECFLAGS']
  161.         
  162.         if 'OPT' in os.environ:
  163.             opt = os.environ['OPT']
  164.         
  165.         cflags = ' '.join((lambda .0: for x in .0:
  166. if x:
  167. str(x)continue)((basecflags, opt, extra_cflags)))
  168.         if 'CFLAGS' in os.environ:
  169.             cflags = ' '.join((lambda .0: for x in .0:
  170. if x:
  171. str(x)continue)((basecflags, opt, os.environ['CFLAGS'], extra_cflags)))
  172.             ldshared = ldshared + ' ' + os.environ['CFLAGS']
  173.         
  174.         if 'CPPFLAGS' in os.environ:
  175.             cpp = cpp + ' ' + os.environ['CPPFLAGS']
  176.             cflags = cflags + ' ' + os.environ['CPPFLAGS']
  177.             ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
  178.         
  179.         cc_cmd = cc + ' ' + cflags
  180.         compiler.set_executables(preprocessor = cpp, compiler = cc_cmd, compiler_so = cc_cmd + ' ' + ccshared, compiler_cxx = cxx, linker_so = ldshared, linker_exe = cc)
  181.         compiler.shared_lib_extension = so_ext
  182.     
  183.  
  184.  
  185. def get_config_h_filename():
  186.     '''Return full pathname of installed pyconfig.h file.'''
  187.     if python_build:
  188.         if os.name == 'nt':
  189.             inc_dir = os.path.join(project_base, 'PC')
  190.         else:
  191.             inc_dir = project_base
  192.     else:
  193.         inc_dir = get_python_inc(plat_specific = 1)
  194.     if get_python_version() < '2.2':
  195.         config_h = 'config.h'
  196.     else:
  197.         config_h = 'pyconfig.h'
  198.     return os.path.join(inc_dir, config_h)
  199.  
  200.  
  201. def get_makefile_filename():
  202.     '''Return full pathname of installed Makefile from the Python build.'''
  203.     if python_build:
  204.         return os.path.join(os.path.dirname(sys.executable), 'Makefile')
  205.     lib_dir = get_python_lib(plat_specific = 1, standard_lib = 1)
  206.     if not sys.pydebug or '_d':
  207.         pass
  208.     return os.path.join(lib_dir, 'config' + '', 'Makefile')
  209.  
  210.  
  211. def parse_config_h(fp, g = None):
  212.     '''Parse a config.h-style file.
  213.  
  214.     A dictionary containing name/value pairs is returned.  If an
  215.     optional dictionary is passed in as the second argument, it is
  216.     used instead of a new dictionary.
  217.     '''
  218.     if g is None:
  219.         g = { }
  220.     
  221.     define_rx = re.compile('#define ([A-Z][A-Za-z0-9_]+) (.*)\n')
  222.     undef_rx = re.compile('/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n')
  223.     while None:
  224.         line = fp.readline()
  225.         if not line:
  226.             break
  227.         
  228.         m = define_rx.match(line)
  229.         if m:
  230.             (n, v) = m.group(1, 2)
  231.             
  232.             try:
  233.                 v = int(v)
  234.             except ValueError:
  235.                 pass
  236.  
  237.             g[n] = v
  238.             continue
  239.         m = undef_rx.match(line)
  240.         if m:
  241.             g[m.group(1)] = 0
  242.             continue
  243.         continue
  244.         return g
  245.  
  246. _variable_rx = re.compile('([a-zA-Z][a-zA-Z0-9_]+)\\s*=\\s*(.*)')
  247. _findvar1_rx = re.compile('\\$\\(([A-Za-z][A-Za-z0-9_]*)\\)')
  248. _findvar2_rx = re.compile('\\${([A-Za-z][A-Za-z0-9_]*)}')
  249.  
  250. def parse_makefile(fn, g = None):
  251.     '''Parse a Makefile-style file.
  252.  
  253.     A dictionary containing name/value pairs is returned.  If an
  254.     optional dictionary is passed in as the second argument, it is
  255.     used instead of a new dictionary.
  256.     '''
  257.     TextFile = TextFile
  258.     import distutils.text_file
  259.     fp = TextFile(fn, strip_comments = 1, skip_blanks = 1, join_lines = 1)
  260.     if g is None:
  261.         g = { }
  262.     
  263.     done = { }
  264.     notdone = { }
  265.     while None:
  266.         line = fp.readline()
  267.         if line is None:
  268.             break
  269.         
  270.         m = _variable_rx.match(line)
  271.         if m:
  272.             (n, v) = m.group(1, 2)
  273.             v = v.strip()
  274.             tmpv = v.replace('$$', '')
  275.             if '$' in tmpv:
  276.                 notdone[n] = v
  277.             else:
  278.                 
  279.                 try:
  280.                     v = int(v)
  281.                 except ValueError:
  282.                     done[n] = v.replace('$$', '$')
  283.  
  284.                 done[n] = v
  285.         continue
  286.         while notdone:
  287.             for name in notdone.keys():
  288.                 value = notdone[name]
  289.                 if not _findvar1_rx.search(value):
  290.                     pass
  291.                 m = _findvar2_rx.search(value)
  292.                 if m:
  293.                     n = m.group(1)
  294.                     found = True
  295.                     if n in done:
  296.                         item = str(done[n])
  297.                     elif n in notdone:
  298.                         found = False
  299.                     elif n in os.environ:
  300.                         item = os.environ[n]
  301.                     else:
  302.                         done[n] = item = ''
  303.                     if found:
  304.                         after = value[m.end():]
  305.                         value = value[:m.start()] + item + after
  306.                         if '$' in after:
  307.                             notdone[name] = value
  308.                         else:
  309.                             
  310.                             try:
  311.                                 value = int(value)
  312.                             except ValueError:
  313.                                 done[name] = value.strip()
  314.  
  315.                             done[name] = value
  316.                             del notdone[name]
  317.                     
  318.                 found
  319.                 del notdone[name]
  320.             
  321.         fp.close()
  322.         g.update(done)
  323.         return g
  324.  
  325.  
  326. def expand_makefile_vars(s, vars):
  327.     '''Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
  328.     \'string\' according to \'vars\' (a dictionary mapping variable names to
  329.     values).  Variables not present in \'vars\' are silently expanded to the
  330.     empty string.  The variable values in \'vars\' should not contain further
  331.     variable expansions; if \'vars\' is the output of \'parse_makefile()\',
  332.     you\'re fine.  Returns a variable-expanded version of \'s\'.
  333.     '''
  334.     while not _findvar1_rx.search(s):
  335.         m = _findvar2_rx.search(s)
  336.         if m:
  337.             (beg, end) = m.span()
  338.             s = s[0:beg] + vars.get(m.group(1)) + s[end:]
  339.             continue
  340.     break
  341.     continue
  342.     return s
  343.  
  344. _config_vars = None
  345.  
  346. def _init_posix():
  347.     '''Initialize the module as appropriate for POSIX systems.'''
  348.     global _config_vars
  349.     g = { }
  350.     
  351.     try:
  352.         filename = get_makefile_filename()
  353.         parse_makefile(filename, g)
  354.     except IOError:
  355.         msg = None
  356.         my_msg = 'invalid Python installation: unable to open %s' % filename
  357.         if hasattr(msg, 'strerror'):
  358.             my_msg = my_msg + ' (%s)' % msg.strerror
  359.         
  360.         raise DistutilsPlatformError(my_msg)
  361.  
  362.     
  363.     try:
  364.         filename = get_config_h_filename()
  365.         parse_config_h(file(filename), g)
  366.     except IOError:
  367.         msg = None
  368.         my_msg = 'invalid Python installation: unable to open %s' % filename
  369.         if hasattr(msg, 'strerror'):
  370.             my_msg = my_msg + ' (%s)' % msg.strerror
  371.         
  372.         raise DistutilsPlatformError(my_msg)
  373.  
  374.     if sys.platform == 'darwin' and 'MACOSX_DEPLOYMENT_TARGET' in g:
  375.         cfg_target = g['MACOSX_DEPLOYMENT_TARGET']
  376.         cur_target = os.getenv('MACOSX_DEPLOYMENT_TARGET', '')
  377.         if cur_target == '':
  378.             cur_target = cfg_target
  379.             os.putenv('MACOSX_DEPLOYMENT_TARGET', cfg_target)
  380.         elif map(int, cfg_target.split('.')) > map(int, cur_target.split('.')):
  381.             my_msg = '$MACOSX_DEPLOYMENT_TARGET mismatch: now "%s" but "%s" during configure' % (cur_target, cfg_target)
  382.             raise DistutilsPlatformError(my_msg)
  383.         
  384.     
  385.     if python_build:
  386.         g['LDSHARED'] = g['BLDSHARED']
  387.     elif get_python_version() < '2.1':
  388.         if sys.platform == 'aix4':
  389.             python_lib = get_python_lib(standard_lib = 1)
  390.             ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
  391.             python_exp = os.path.join(python_lib, 'config', 'python.exp')
  392.             g['LDSHARED'] = '%s %s -bI:%s' % (ld_so_aix, g['CC'], python_exp)
  393.         elif sys.platform == 'beos':
  394.             python_lib = get_python_lib(standard_lib = 1)
  395.             linkerscript_path = string.split(g['LDSHARED'])[0]
  396.             linkerscript_name = os.path.basename(linkerscript_path)
  397.             linkerscript = os.path.join(python_lib, 'config', linkerscript_name)
  398.             g['LDSHARED'] = '%s -L%s/lib -lpython%s' % (linkerscript, PREFIX, get_python_version())
  399.         
  400.     
  401.     _config_vars = g
  402.  
  403.  
  404. def _init_nt():
  405.     '''Initialize the module as appropriate for NT'''
  406.     global _config_vars
  407.     g = { }
  408.     g['LIBDEST'] = get_python_lib(plat_specific = 0, standard_lib = 1)
  409.     g['BINLIBDEST'] = get_python_lib(plat_specific = 1, standard_lib = 1)
  410.     g['INCLUDEPY'] = get_python_inc(plat_specific = 0)
  411.     g['SO'] = '.pyd'
  412.     g['EXE'] = '.exe'
  413.     g['VERSION'] = get_python_version().replace('.', '')
  414.     g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable))
  415.     _config_vars = g
  416.  
  417.  
  418. def _init_mac():
  419.     '''Initialize the module as appropriate for Macintosh systems'''
  420.     global _config_vars
  421.     g = { }
  422.     g['LIBDEST'] = get_python_lib(plat_specific = 0, standard_lib = 1)
  423.     g['BINLIBDEST'] = get_python_lib(plat_specific = 1, standard_lib = 1)
  424.     g['INCLUDEPY'] = get_python_inc(plat_specific = 0)
  425.     import MacOS as MacOS
  426.     if not hasattr(MacOS, 'runtimemodel'):
  427.         g['SO'] = '.ppc.slb'
  428.     else:
  429.         g['SO'] = '.%s.slb' % MacOS.runtimemodel
  430.     g['install_lib'] = os.path.join(EXEC_PREFIX, 'Lib')
  431.     g['install_platlib'] = os.path.join(EXEC_PREFIX, 'Mac', 'Lib')
  432.     g['srcdir'] = ':'
  433.     _config_vars = g
  434.  
  435.  
  436. def _init_os2():
  437.     '''Initialize the module as appropriate for OS/2'''
  438.     global _config_vars
  439.     g = { }
  440.     g['LIBDEST'] = get_python_lib(plat_specific = 0, standard_lib = 1)
  441.     g['BINLIBDEST'] = get_python_lib(plat_specific = 1, standard_lib = 1)
  442.     g['INCLUDEPY'] = get_python_inc(plat_specific = 0)
  443.     g['SO'] = '.pyd'
  444.     g['EXE'] = '.exe'
  445.     _config_vars = g
  446.  
  447.  
  448. def get_config_vars(*args):
  449.     """With no arguments, return a dictionary of all configuration
  450.     variables relevant for the current platform.  Generally this includes
  451.     everything needed to build extensions and install both pure modules and
  452.     extensions.  On Unix, this means every variable defined in Python's
  453.     installed Makefile; on Windows and Mac OS it's a much smaller set.
  454.  
  455.     With arguments, return a list of values that result from looking up
  456.     each argument in the configuration variable dictionary.
  457.     """
  458.     global _config_vars
  459.     if _config_vars is None:
  460.         func = globals().get('_init_' + os.name)
  461.         if func:
  462.             func()
  463.         else:
  464.             _config_vars = { }
  465.         _config_vars['prefix'] = PREFIX
  466.         _config_vars['exec_prefix'] = EXEC_PREFIX
  467.         if sys.platform == 'darwin':
  468.             kernel_version = os.uname()[2]
  469.             major_version = int(kernel_version.split('.')[0])
  470.             if major_version < 8:
  471.                 for key in ('LDFLAGS', 'BASECFLAGS', 'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
  472.                     flags = _config_vars[key]
  473.                     flags = re.sub('-arch\\s+\\w+\\s', ' ', flags)
  474.                     flags = re.sub('-isysroot [^ \t]*', ' ', flags)
  475.                     _config_vars[key] = flags
  476.                 
  477.             elif 'ARCHFLAGS' in os.environ:
  478.                 arch = os.environ['ARCHFLAGS']
  479.                 for key in ('LDFLAGS', 'BASECFLAGS', 'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
  480.                     flags = _config_vars[key]
  481.                     flags = re.sub('-arch\\s+\\w+\\s', ' ', flags)
  482.                     flags = flags + ' ' + arch
  483.                     _config_vars[key] = flags
  484.                 
  485.             
  486.             m = re.search('-isysroot\\s+(\\S+)', _config_vars['CFLAGS'])
  487.             if m is not None:
  488.                 sdk = m.group(1)
  489.                 if not os.path.exists(sdk):
  490.                     for key in ('LDFLAGS', 'BASECFLAGS', 'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
  491.                         flags = _config_vars[key]
  492.                         flags = re.sub('-isysroot\\s+\\S+(\\s|$)', ' ', flags)
  493.                         _config_vars[key] = flags
  494.                     
  495.                 
  496.             
  497.         
  498.     
  499.     if args:
  500.         vals = []
  501.         for name in args:
  502.             vals.append(_config_vars.get(name))
  503.         
  504.         return vals
  505.     return _config_vars
  506.  
  507.  
  508. def get_config_var(name):
  509.     """Return the value of a single variable using the dictionary
  510.     returned by 'get_config_vars()'.  Equivalent to
  511.     get_config_vars().get(name)
  512.     """
  513.     return get_config_vars().get(name)
  514.  
  515.